#pragma once
#ifndef _GAME_H_
#define _GAME_H_
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "Input.h"
#include "Config.h"
#include "Trace.h"

#define KEY_DOWN(code) ( IsKeyDown(code) )

class CGame
{
protected:
	LPDIRECT3D9 mD3d;
	LPDIRECT3DDEVICE9 mD3dDv;
	LPDIRECT3DSURFACE9 mBackBuffer;
	// Handle of the Game Window
	HWND mHWnd;
	LPD3DXSPRITE mSpriteHandler;
	HINSTANCE mHInstance;
	
	// Time between the last frame and current frame
	DWORD mDeltaTime;		
	// Screen mode 
	int mMode;		
	// Is running in fullscreen mode?
	int mIsFullScreen;	
	// Frame rate
	int mFrameRate;
	int mScreenWidth;
	int mScreenHeight;
	int mDepth;

	D3DFORMAT mBackBufferFormat;
	// Name of game will be used as Window Class Name
	LPWSTR mName;	

	void InitWindow();
	void InitDirectX();
	void InitKeyboard();

	// Place holder for sub classes
	virtual void LoadResources();
	virtual void ProcessInput();
	virtual void GameUpdate(int deltaTime);
	virtual void GameRender();
	virtual void UnloadResources();

	// Render a single frame
	void Render();

	void ProcessKeyBoard();
	void SetScreenDimension(int mode);

	static LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
public:
	LPDIRECT3D9 GetDirectX();
	LPDIRECT3DDEVICE9 GetDevice();
	LPDIRECT3DSURFACE9 GetBackBuffer();

	int GetMode();
	int GetScreenWidth();
	int GetScreenHeight();
	int GetDepth();	

	CGame(HINSTANCE hInstance, LPWSTR name, int mode, int isFullScreen, int frameRate);
	
	// Initialize the game with set parameters
	void Init();
	// Loop game
	void GameLoop();

	~CGame();
};

#endif

